package com.tools.wechat.msgexport.generator;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;
import com.tools.wechat.msgexport.generator.config.CommonConfiguration;

/**
 * @author 辰雨期
 * Created by 辰雨期 on 2021/8/7.
 */
public class CreateFile {
    // 经常修改
    private static String tableName = "payment";
    // 一般不用改
    private static String tablePrefix = "";
    private static String basePackageName = "com.tools.cloud.payment.modules";
    private static String operProjectName = "cloud-provider-payment8001";


    public static void main(String[] args) {
        // 全局配置
        GlobalConfig config =
                CommonConfiguration.getGlobalConfig(operProjectName, false, null);

        // 数据源配置
        DataSourceConfig dataSourceConfig =
                CommonConfiguration.getDataSourceConfig(DbType.MYSQL);

        // 生成策略配置
        StrategyConfig stConfig =
                CommonConfiguration.getStrategyConfig(tableName, tablePrefix);

        // 包名配置
        PackageConfig pkConfig =
                CommonConfiguration.getPackageConfig(tableName, tablePrefix, basePackageName);
        CommonConfiguration.changeMapperPath(operProjectName,false);

        // 代码模板配置
        TemplateConfig templateConfig =
                CommonConfiguration.getTemplateConfig();

        // 自定义配置
        InjectionConfig cfg =
                CommonConfiguration.getInjectionConfig();

        // 生成器
        AutoGenerator generator = new AutoGenerator();
        generator.setCfg(cfg)
                 .setGlobalConfig(config)
                 .setDataSource(dataSourceConfig)
                 .setStrategy(stConfig)
                 .setPackageInfo(pkConfig)
                 .setTemplate(templateConfig);
        generator.execute();
    }
}
